﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using NetBay.Core.BusinessEntities.Workflow;
using Rio.Applications.Web.RioWCFWorkflow;
using Rio.Framework.Localisation;

namespace Rio.Framework.Pages.Workflow.Actions
{
    [InheritedExport(typeof(WorkflowButtonAction))]
    public class RefuseWorkflowButtonAction : WorkflowButtonAction
    {
        public RefuseWorkflowButtonAction()
            : base()
        {
            Text = Resx.GetLabel(ResxWorkflow.WorkflowAction_Refuse);
            Image = new Uri("/Rio.Framework.Pages;component/Assets/Images/refuse.png", UriKind.Relative);
            UiTypeAction = WorkflowTypeAction.Refuse;
        }

        protected override void ActionClicked()
        {
            CommentWindow commentwindow = new CommentWindow();
            commentwindow.Closed += delegate
            {
                if (commentwindow.DialogResult != null && commentwindow.DialogResult == true)
                {
                    //Execute action with the refuse comment
                    ExecuteAction(
                        new List<Parameter>()
                            {
                                new Parameter()
                                    {
                                        ParameterName = "COMMENT",
                                        ParameterValue = commentwindow.Comment
                                    }
                            });
                }
            };

            commentwindow.ShowDialog();
        }
    }

    public class RefuseAllWorkflowButtonAction : RefuseWorkflowButtonAction
    {
        public RefuseAllWorkflowButtonAction()
            : base()
        {
            Text = Resx.GetLabel(ResxWorkflow.WorkflowAction_RefuseAll);
            IsGlobalAction = true;
        }
    }
}
